// 创建基础配置项
var hook = document.getElementById('other_hook');
var submit = document.getElementById('submit_code');
(() => {
    chrome.storage.sync.get(['hook_id'], (e) => {
        var hook_id = e.hook_id;
        if (!hook_id) return;
        chrome.storage.sync.get(['code'], (e) => { 
            hook.value = e.code[hook_id-1].code;
            chrome.storage.sync.set({ 'hook_id': 0 })
        })
    });
})();
submit.addEventListener('click', () => {
    alert('提交hook代码成功！')
    var hook_code = hook.value;
    if (!hook_code) { alert('请先输入hook代码'); return; }
    chrome.storage.sync.get(['code'], (e) => { 
        var content = e;
        if(!e.code){
            content = { 'code': []};
        }else if (Object.values(content.code).every((e)=>{return (e==null)})) {
            content = { 'code': [] };
        };
        var code = {
            name: prompt('hook_name'),
            desc: prompt('hook_desc'),
            code: hook_code,
            state: 1
        };
        content.code.push(code);
        chrome.storage.sync.set(content, () => {});
        alert('hook内容：' + hook_code)
    });
})
